package com.ogawa.health.code.service;

import com.ogawa.health.code.dao.GeneratorDao;
import com.ogawa.health.code.utils.GenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 代码生成器
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年12月19日 下午3:33:38
 */
@Service
public class GeneratorService {
	@Autowired
	private GeneratorDao generatorDao;

	public List<Map<String, Object>> queryList(Map<String, Object> map) {
		return generatorDao.queryList(map);
	}

	public int queryTotal(Map<String, Object> map) {
		return generatorDao.queryTotal(map);
	}

	public Map<String, String> queryTable(String tableName) {
		return generatorDao.queryTable(tableName);
	}

	public List<Map<String, String>> queryColumns(String tableName) {
		return generatorDao.queryColumns(tableName);
	}

	public void generatorCode(String[] tableNames) {

		for(String tableName : tableNames){
			//查询表信息
			Map<String, String> table = queryTable(tableName);
			//查询列信息
			List<Map<String, String>> columns = queryColumns(tableName);
			//生成代码
			GenUtils.generatorCode(table, columns, null);
		}
	}
}
